/**
 * 
 */
package com.epart.widget.module.component;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import com.epart.widget.domain.BoardConfig;
import com.epart.widget.module.board.BoardService;

/**
 * 메뉴바 컴포넌트
 * 
 * @author cwsong
 * @version 2011. 3. 10.
 */
public class WcmsWidgetMenuBar extends JMenuBar {

	private ActionMap actionMap;
	private final String DEFAULT_VERSION_TITLE = "버전정보";
	private WcmsWidget wcmsWidget;
	private BoardService boardService;

	/**
	 * @param boardService
	 *            the boardService to set
	 */
	public void setBoardService(BoardService boardService) {
		this.boardService = boardService;
	}

	/**
	 * @param wcmsWidget
	 *            the wcmsWidget to set
	 */
	public void setWcmsWidget(WcmsWidget wcmsWidget) {
		this.wcmsWidget = wcmsWidget;
	}
	
	/**
	 * 생성자
	 */
	public WcmsWidgetMenuBar() {
		createActionMap();
	}
	
	/**
	 * 메뉴바를 만든다. 
	 */
	public void createMenuBar(){
		JMenu home = new JMenu("홈");
		add(home);

		JMenu board = new JMenu("게시판");
		add(board);
		
		List<BoardConfig> boardConfigList = boardService.getBoardConfigList();
		for(BoardConfig boardConfig : boardConfigList){
			JMenuItem boardConfigMenu = new JMenuItem(boardConfig.getBoardConfigTitle());
			board.add(boardConfigMenu);
		}

		JMenu link = new JMenu("링크");
		add(link);

		JMenu info = new JMenu("정보");
		add(info);

		JMenuItem help = new JMenuItem("도움말");
		info.add(help);

		JMenuItem version = new JMenuItem(actionMap.get("version"));
		version.setText("버전");
		info.add(version);
	}

	private void createActionMap() {
		this.actionMap = new ActionMap();
		actionMap.put("version", new VersionAction());
		// actionMap.put("board", new BoardAction());
	}

	private class VersionAction extends AbstractAction {
		@Override
		public void actionPerformed(ActionEvent e) {
			JOptionPane.showMessageDialog(wcmsWidget, "ver 0.0.1 Epart.", DEFAULT_VERSION_TITLE, JOptionPane.INFORMATION_MESSAGE);
		}
	}

	private class BoardAction extends AbstractAction {
		@Override
		public void actionPerformed(ActionEvent e) {

		}
	}

}
